package com.weai.controller;

import com.weai.dto.ApiResponse;
import com.weai.dto.DepositAIChatRequest;
import com.weai.dto.DepositAIChatResponse;
import com.weai.service.DepositAIService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * DeepSeek AI助手控制器
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/depositai")
@Tag(name = "存款AI助手", description = "提供基于大模型的智能对话服务")
public class DepositAIController {

    /**
     * AI助手服务
     */
    private final DepositAIService depositAIService;

    /**
     * 处理与AI助手的对话请求
     *
     * @param request 聊天请求
     * @return 包含AI回复的响应对象
     */
    @PostMapping("/chat")
    @Operation(summary = "发送消息给AI助手", description = "处理用户消息并返回AI助手的回复")
    public ApiResponse<DepositAIChatResponse> chat(@Valid @RequestBody DepositAIChatRequest request) {
        log.info("收到AI对话请求: {}", request.toString());
        DepositAIChatResponse response = depositAIService.chat(request, request.getUsername());
        log.info("AI对话响应: {}", response);
        return ApiResponse.success(response);
    }


    @PostMapping("/wechat")
    @Operation(summary = "发送消息给AI助手", description = "处理用户消息并返回AI助手的回复")
    public ApiResponse<DepositAIChatResponse> chat(
            @RequestParam("request") @Valid String request,
            @RequestParam("username") String username) {
        
        log.info("收到企业微信AI服务助手对话请求: 用户={}, 内容={}", username, request);
        DepositAIChatResponse response = depositAIService.weChat(request, username);
        log.info("企业微信AI服务助手对话响应: {}", response);
        return ApiResponse.success(response);
    }
} 